<?php
print '<h3 id="tlh">';
	$timed ? __('Timed') : __('Messages');
print '</h3>';
print $html->image('ajax-loader.gif',
										  array(
													'id' => 'ajaxloaderMess',
													'style' => 'display: none',
													'alt' => __('Ajax loading indicator', true),
													'title' => __('Getting new messages', true)
												 )
										  );


print '<div id="timeline">';
foreach($messages as $key => $m){

	print '<div class="entry">';
		print '<div class="logos">';
			print '<span>';
				if($timed)
					print $html->image('clock.png', array(
															'title' => __('This message will be sent at ' . $m['Message']['created'], true),
															'alt' => __('This message will be sent at ' . $m['Message']['created'], true),
															'class' => 'inactive_timed'
															));
				foreach($m['Account'] as $acc){
					$error = isset($acc['AccountsMessage']['error']) ? $acc['AccountsMessage']['error'] : null;
					print $html->image('logo_'.$acc['Community']['name'].'.png',
							 array(
									 'alt' => $acc['Community']['name'] . '/' . $acc['username'],
									 'title' => $error ? __('Error sending to ', true) . $acc['Community']['name'] . '/' . $acc['username'] : $acc['Community']['name'] . '/' . $acc['username'],
									 'class' => $error ? 'error_logo' : 'active_logo'
									 )
							 );
				}
			print '</span>';
		print '</div>';

		$cssClass = ($key % 2) ? 'odd' : '';
		print '<div class="m '.$cssClass.'">';
			print $html->image('trash.png',
											array(
												'class' => 'trash',
												'id' => 'd' . $m['Message']['id'],
												'alt' => __('Delete from queue', true),
												'title' => __('Delete from queue', true)
											)
										);
			if(isset($acc['avatar'])){
				$avatar = $acc['avatar'];
				//print $html->link(
				print $html->image(
											$avatar,
											array(
												'class' => 'mygravatar',
												'alt' => $acc['username'],
												'title' => $acc['username'],
												'height' => 48,
												'width' => 48
											)
										);
										/*$acc['url'],
										null, null, false
									  );*/
			}
			else{
				$avatar = 'http://www.gravatar.com/avatar/'.md5(strtolower($session->read('Auth.User.email'))).'.jpg?s=60&d=' . urlencode($html->url('/img/no_avatar.png'));
				print $html->image(
						$avatar,
						array(
							'class' => 'mygravatar'
						)
						);
			}
			print '<p>';
				print preg_replace('|(http://\S*)|', '<a href="\1" target="_blank">\1</a>', $m['Message']['message']);
			print '</p>';
			print '<p class="mtime">';
				foreach($m['Account'] as $acc){
					//if(isset($acc['url']))
						//print $html->link('@'.$acc['username'], $acc['url'], array('class' => 'mu'), null, false);
					//else
						print '<span class="mu">@'.$acc['username'].'</span>';
				}
				print $m['Message']['created'];
			print '</p>';
		print '</div>';

	print '</div>';
}
print '</div>';
?>